package com.gimi.cloud.bbp.app.consumer.service.mall.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.gimi.cloud.bbp.app.consumer.feign.mall.MallMessageFeignService;
import com.gimi.cloud.bbp.app.consumer.service.mall.MallMessageService;
import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.exception.MsgException;
import com.gimi.cloud.bbp.common.utils.reqhead.Util;
import com.gimi.cloud.bbp.dto.mall.MallMessageDTO;

@Service
public class MallMessageServiceImpl implements MallMessageService{
	
	@Autowired private MallMessageFeignService feignService;
	
	@Override
	public void getMessageListByReceiveUser(String requestData, HttpServletRequest request, HttpServletResponse response) {
		MallMessageDTO mallMessageDTO = JSON.parseObject(requestData,MallMessageDTO.class);
		if (mallMessageDTO.get_userId() == null) {
			throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
		}
		Util.sendResponse(feignService.getMessageListByReceiveUser(mallMessageDTO), response);
	}
	
	@Override
	public void userDelMessageByMeId(String requestData, HttpServletRequest request, HttpServletResponse response) {
		MallMessageDTO mallMessageDTO = JSON.parseObject(requestData,MallMessageDTO.class);
		if (mallMessageDTO.getMeId() == null) {
			throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
		}
		Util.sendResponse(feignService.userDelMessageByMeId(mallMessageDTO), response);
	}
	
	@Override
	public void getMessageByMeId(String requestData, HttpServletRequest request, HttpServletResponse response) {
		MallMessageDTO mallMessageDTO = JSON.parseObject(requestData,MallMessageDTO.class);
		if (mallMessageDTO.getMeId() == null) {
			throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
		}
		Util.sendResponse(feignService.getMessageByMeId(mallMessageDTO), response);
	}
	
	@Override
	public void getMessageByUserIdAndStatus(String requestData, HttpServletRequest request, HttpServletResponse response) {
		MallMessageDTO mallMessageDTO = JSON.parseObject(requestData,MallMessageDTO.class);
		if (mallMessageDTO.get_userId() == null) {
			throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
		}
		Util.sendResponse(feignService.getMessageByUserIdAndStatus(mallMessageDTO), response);
	}

	

}
